Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: adds type #313

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat!: adds type #313

wants to merge 1 commit into from

Conversation

reggi
Copy link
Contributor

@reggi reggi commented Nov 22, 2024

Adds type to package.json for use when running npm init.

  1. Defaults to commonjs
  2. Validates against commonjs | module
  3. Allows npm init --init-type module -y
  4. Allows for init.type=module in .npmrc
  5. Improved tests to make it easier to manage removing / adding new prompts

on the shoulders of #302
a part of the npm 11 roadmap npm/statusboard#898
statusboard issue here npm/statusboard#654
older rfc npm/rfcs#347

Note: Running npm init --init-type=module -y will not overwrite an existing package.json type field. This is deemed out of scope for init. To update an existing type edit it manually or field, use jq '.type = "module"' package.json > tmp.json && mv tmp.json package.json.

@reggi reggi requested a review from a team as a code owner November 22, 2024 20:21
Copy link

@jumoel jumoel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change!

if (['commonjs', 'module'].includes(type)) {
return type
}
throw new Error(`${type} is not a valid package "type" (must be "commonjs" or "module")`)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider letting the error message be generated by the same array you use to perform the actual validation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a new type is added to the spec, it will mean existing versions of npm will not be able to specify them. We'll have to explicitly add it to npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants